#ifndef __ARGOPT_H__
#define __ARGOPT_H__

#ifdef __cplusplus
extern "C" {
#endif
#include <stddef.h>
#include <stdint.h>
	enum {
		ARGOPT_DATAENABLE = 0X01, // 需要设置数据
	};
	typedef struct argopt_st argopt_t;
	typedef struct argopt_ctl_st argopt_ctl_t;
	struct argopt_st
	{
		char opt;
		uint8_t state;
		int (*action_impl)(argopt_ctl_t *ctl, argopt_t *self, const char *arg);
		void (*free_impl)(argopt_t *self);
		void *data;
	};
#define argopt(opt,state,action,free) {opt,state,action,free,NULL}
#define argopt_arr_len(arr) (sizeof(arr)/sizeof(argopt_t))
#define argopt_buf_len(arr) (argopt_arr_len(arr) * 2 +1)
	struct argopt_ctl_st
	{
		char *optbuf;
		argopt_t *arr;
		size_t len;
	};
#define argopt_ctl() {NULL,NULL,0}
	extern int argopt_ctl_init(argopt_ctl_t *ctl, argopt_t *arr, size_t len, int argc, char *argv[]);
	extern void *argopt_ctl_getdata(argopt_ctl_t *ctl, char opt);
	extern void argopt_ctl_setdata(argopt_ctl_t *ctl, char opt, void *data);
	extern void argopt_setdata(argopt_t *argopt, void *data);
	extern void argopt_ctl_deinit(argopt_ctl_t *ctl);

#ifdef __cplusplus
}
#endif

#endif